package com.example.test;

import org.openjdk.jol.info.ClassLayout;

import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author shanchong
 * @date 2021/2/21
 **/
public class Markword {
    //-XX:+UseBiasedLocking -XX:BiasedLockingStartupDelay=0
    public static void main(String[] args) throws InterruptedException {
//        TimeUnit.SECONDS.sleep(5);
        Main main = new Main();
//        System.out.println(ClassLayout.parseInstance(main).toPrintable());
//        int i = main.hashCode();
//        System.out.println(i);
//        System.out.println(ClassLayout.parseInstance(main).toPrintable());

//        synchronized (main){
//            System.out.println(ClassLayout.parseInstance(main).toPrintable());
//        }
        PrintStream out = System.out;
        Thread thread = new Thread(() -> {
            synchronized (main) {
                out.println(Thread.currentThread().getId()+"0-----"+ClassLayout.parseInstance(main).toPrintable());
            }
        });
        thread.start();
        TimeUnit.SECONDS.sleep(1);
//        thread.interrupt();
        TimeUnit.SECONDS.sleep(1);
//        System.out.println(thread);
//        thread.interrupt();
        new Thread(()->{
            synchronized (main) {
                out.println(thread.getState()+"-"+Thread.currentThread().getId()+"-1-----"+ClassLayout.parseInstance(main).toPrintable());
            }
        }).start();
        TimeUnit.SECONDS.sleep(1);
//        System.out.println("2-----"+ClassLayout.parseInstance(main).toPrintable());
//        synchronized (main) {
//            out.println("3-----"+ClassLayout.parseInstance(main).toPrintable());
//        }
    }
}
